<template>
  <view class="product-item row p-2 border-bottom border-light-secondary animated fadeIn faster" @click="openDetail">
    <!-- 商品图片 -->
    <view class="span-6">
      <image 
        :src="item.titlepic" 
        mode="widthFix" 
        class="w-100 lazy-load"
        alt="商品图片"
      ></image>
    </view>
    <!-- 商品信息 -->
    <view class="span-14 pl-3 d-flex flex-column">
      <!-- 商品标题 -->
      <view class="font-md font-weight text-overflow-ellipsis">{{ item.title }}</view>
      
      <!-- 商品描述 -->
      <view class="font text-light-muted line-h-md mb-auto text-overflow-ellipsis">
        {{ item.desc }}
      </view>
      
      <!-- 商品价格 -->
      <price :text="item.pprice" />
      
      <!-- 商品评论和满意度 -->
      <view class="font-sm text-light-muted">
        {{ item.comment_num }} 条评论 | {{ item.good_num }} 满意
      </view>
    </view>
  </view>
</template>

<script>
  import price from "@/components/common/price.vue";

  export default {
    components: {
      price
    },
    props: {
      item: Object,
      index: Number
    },
    methods: {
      // 跳转到商品详情页
      openDetail() {
        uni.navigateTo({
          url: '/pages/detail/detail?detail=' + JSON.stringify(this.item)
        });
      }
    }
  };
</script>

<style scoped>
  .product-item {
    position: relative;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
  }

  .product-item:hover {
    background-color: #f9f9f9;
    cursor: pointer;
  }

  .product-item .span-6 {
    width: 100px; /* 固定宽度 */
    height: 100px; /* 固定高度 */
  }

  .product-item .span-14 {
    flex: 1;
  }

  .product-item .font-md {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .product-item .font-sm {
    font-size: 12px;
  }

  .product-item .text-light-muted {
    color: #888;
  }

  .product-item .line-h-md {
    line-height: 1.5;
  }

  .product-item .text-overflow-ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .lazy-load {
    display: block;
    object-fit: cover;
  }
</style>
